<template>
  <div class="time-viewer">{{ dateTime }}</div>
</template>

<script>
import { parseTime } from "@/utils";
let timer = null;
export default {
  data() {
    return {
      dateTime: ""
    };
  },
  created() {
    this.getTime();
  },
  destroyed() {
    clearInterval(timer)
  },
  methods: {
    getTime() {
      timer = setInterval(() => {
        const time = new Date();
        this.dateTime = parseTime(time);
      }, 500);
    }
  }
};
</script>

<style lang="scss" scoped>
.time-viewer {
  margin-right: 30px;
}
</style>
